package entities;

import java.util.ResourceBundle;
import java.util.Vector;

/**
 * Entity Class for Participants. A particpant is a member with a rating.
 * 
 * @author MK
 * 
 */
public class Participant {

	private Member member;
	private int rating;

	private Participant() {
		super();
	}

	public Participant(Member member, int rating) {
		super();

		this.member = member;
		this.rating = rating;
	}

	public Participant(Participant participant) {
		this(participant.member, participant.rating);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((member == null) ? 0 : member.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Participant other = (Participant) obj;
		if (member == null) {
			if (other.member != null)
				return false;
		} else if (!member.equals(other.member))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Participant [member=" + member + ", rating=" + rating + "]";
	}

	public int compareTo(Participant participant) {
		return this.member.compareTo(participant.member);
	}

	public Member getMember() {
		return member;
	}

	public int getRating() {
		return rating;
	}

	public static Vector<String> attributeNamesShort() {
		ResourceBundle resBundle = ResourceBundle
				.getBundle("bundles.MessagesBundle");

		Vector<String> vector = new Vector<String>();
		vector.add(resBundle.getString("nameLast"));
		vector.add(resBundle.getString("nameFirst"));
		vector.add(resBundle.getString("rating"));

		return vector;
	}

	public Vector<String> asShortVector() {

		Vector<String> vector = new Vector<String>();

		vector.add(this.member.getNameLast());
		vector.add(this.member.getNameFirst());
		if (this.rating == 0) {
			vector.add("---");
		} else {
			vector.add("" + this.rating);
		}
		return vector;
	}
}
